﻿using System;
namespace ZhhbSoft.Data
{
    /// <summary>
    /// 可用于数据源自动赋值的属性
    /// </summary>
    public class DataMember : Attribute
    {
        /// <summary>
        /// 对应字段名
        /// </summary>
        private string _fieldName = "";

        /// <summary>
        /// 是否自动生成
        /// </summary>
        public bool AutoGenerate { get; set; }

        /// <summary>
        /// 对应字段名
        /// </summary>
        public string FieldName
        {
            get { return _fieldName; }
            set { _fieldName = value; }
        }

        /// <summary>
        /// 是否可保存
        /// </summary>
        public bool SaveAble { get; set; }

        public DataMember()
            : this("")
        {
        }

        public DataMember(bool saveAble)
            : this("", saveAble)
        {
        }
        public DataMember(string fieldName)
            : this(fieldName, true)
        {
        }
        public DataMember(bool saveAble, string fieldName)
            : this(fieldName, saveAble)
        {

        }
        public DataMember(string fieldName, bool saveAble)
            : this(fieldName, saveAble, false)
        {

        }
        public DataMember(bool saveAble, bool autoGenerate)
            : this("", saveAble, autoGenerate)
        {
        }
        public DataMember(bool saveAble, bool autoGenerate, string fieldName)
            : this(fieldName, saveAble, autoGenerate)
        {
        }
        public DataMember(bool saveAble, string fieldName, bool autoGenerate)
            : this(fieldName, saveAble, autoGenerate)
        {
        }
        public DataMember(string fieldName, bool saveAble, bool autoGenerate)
        {
            _fieldName = fieldName;
            SaveAble = saveAble;
            AutoGenerate = autoGenerate;
        }
    }
    public delegate void ConvertDataItemToObject();
}
